<?php

class UserIdentity extends CUserIdentity {
	private $id;
	
	public function authenticate() {
		
		$username=strtolower($this->username); 
		$user=Users::model()->find('LOWER(name)=?',array($username)); 
		if($user===null)
		{ 
			$this->errorCode=self::ERROR_USERNAME_INVALID; 
		}
		else if(sha1($this->password)!==$user->password)
		{
			$this->errorCode=self::ERROR_PASSWORD_INVALID; 
		}
		else
		{
			$this->id=$user->id; 
			$this->username=$user->name; 
			$this->errorCode=self::ERROR_NONE;
		}

		return !$this->errorCode;
	}

	public function getId() {
		return $this->id;
	}
	
}